package com.findyou.result;

/**
 * @Title: Result
 * @Author 贾金博
 * @Package com.findyou.result
 * @Date 2025/6/8 上午11:04
 * @description: 永运规范化返回给前端数据响应
 */
import lombok.Data;

/**
 * 统一返回结果类
 */
@Data
public class Result<T> {
    /**
     * 状态码
     */
    private Integer code;

    /**
     * 消息
     */
    private String msg;

    /**
     * 数据
     */
    private T data;

    /**
     * 构造方法
     */
    public Result() {
    }

    public Result(Integer code, String message) {
        this.code = code;
        this.msg = message;
    }

    public Result(Integer code, String message, T data) {
        this.code = code;
        this.msg = message;
        this.data = data;
    }

    /**
     * 成功的静态方法
     */
    public static <T> Result<T> success(T data) {
        return new Result<>(200, "成功", data);
    }

    public static <T> Result<T> success() {
        return new Result<>(200, "成功", null);
    }

    public static <T> Result<T> success(String message, T data) {
        return new Result<>(200, message, data);
    }

    /**
     * 失败的静态方法
     */
    public static <T> Result<T> fail(Integer code, String message) {
        return new Result<>(code, message, null);
    }

    public static <T> Result<T> fail(String message) {
        return new Result<>(500, message, null);
    }

    public static <T> Result<T> fail(Integer code, String message, T data) {
        return new Result<>(code, message, data);
    }

}
